package Com.javaserver.servlet;

import Com.javaserver.bean.rewland;
import Com.javaserver.bean.salary;
import Com.javaserver.dao.salaryserver;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.List;
@WebServlet("/saadd")
public class salaryaddserverlet extends HttpServlet {
    salaryserver sa=new salaryserver();

    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        doPost(req,resp);
    }

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        resp.setCharacterEncoding("UTF-8");
        req.setCharacterEncoding("UTF-8");
         salary s=new salary();
         s.setX_id(Integer.parseInt(req.getParameter("id")));
         s.setX_name(req.getParameter("name"));
        s.setX_month(req.getParameter("month"));
        s.setX_basepay(req.getParameter("basepay"));
        s.setX_overtimepay(req.getParameter("overtimepay"));
        s.setX_expenses(req.getParameter("expenses"));
        s.setX_attendance(req.getParameter("attendance"));
        s.setX_absenteeism(req.getParameter("absenteeism"));
        s.setX_insurance(req.getParameter("insurance"));
        s.setX_wages(req.getParameter("wages"));
        if (sa.saadd(s)==null){
            req.getSession().setAttribute("msg","添加失败");
            resp.sendRedirect(req.getContextPath()+"/AddSalary.jsp");
        }else {
            //这个地方放重新刷新的页面List
            List<salary> list=sa.salist(1);
            req.getSession().setAttribute("salarylist",list);
            req.getSession().setAttribute("msg","添加成功");
            resp.sendRedirect(req.getContextPath()+"/salary");
        }


    }
}
